/*
 * @Description: 
 * @Version: 1.0
 * @Autor: ziwei
 * @Date: 2021-06-09 18:29:04
 * @LastEditors: ziwei
 * @LastEditTime: 2021-06-10 10:26:46
 */
let queue = [];//这里存放要更新的watcher
let has ={};//用来存储已有的watcher的id

function flushScchedulerQueue() {
  queue.forEach(watcher=>watcher.run());
        queue = [];//这里存放要更新的watcher
        has = {};
        pending= false
}

let pending = false;//是否是等待的
export function queueWatcher(watcher) {//watcher1  watcher1 watcher1 watcher1 watcher2
  //一般情况下 写去重 可以采用这种方式 如果你不使用set的时候
  let id=watcher.id;
  if(has[id]==null){
    has[id]=true
    queue.push(watcher);
    if(!pending){//防抖  多次执行 只走一次
      nextTick(flushScchedulerQueue);
      pending=true;
    }

  }
}